import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Solution1331 {
    public int[] arrayRankTransform(int[] arr) {
        Map<Integer,Integer> map=new HashMap<>();
        int[] f= Arrays.copyOf(arr,arr.length);
        Arrays.sort(f);
        int count=1;
        for (int i : f) {
            if (!map.containsKey(i)){
                map.put(i,count);
                count++;
            }
        }
        int[] g=new int[arr.length];
        for (int i=0;i<g.length;i++){
            g[i]=map.get(arr[i]);
        }
        return g;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1331().arrayRankTransform(new int[]{40, 10, 20, 30})));
    }
}
